<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#div{
			width:200px;
			height: 200px;
			border: 2px solid black;
			}
		</style>
	</head>
	<body>
		<h2>点击变色</h2>
		<div id="div" onclick="change()"></div>
	    <script>
	    	function change(){
	    	var	 bg=document.getElementById('div');
	    	bg.style.backgroundColor=
                ( bg.style.backgroundColor=='red'?'green':'red');
	    	}
	    </script>
	</body>
</html>
